package com.tanhua.server.service;

import com.tanhua.dubbo.api.QuestionApi;
import com.tanhua.model.domain.Question;
import com.tanhua.server.interceptor.UserHolder;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class QuestionService {

    @DubboReference
    private QuestionApi questionApi;


    /**
     * 设置陌生人问题
     * @param content
     */
    public void saveQuestions(String content) {
        //1.获取id
        Long userId = UserHolder.getUserId();
        //2.调用api查看陌生人问题
        Question question = questionApi.findById(userId);
        //3.判断问题是否存在
        if (question == null) {
            //不存在就添加
            question = new Question();
            question.setUserId(userId);
            question.setTxt(content);
            questionApi.save(question);
        } else {
            //存在就更新
            question.setTxt(content);
            questionApi.update(question);
        }
    }
}
